import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { resolve } from 'path';

export default defineConfig({
  plugins: [
    dts({
      insertTypesEntry: true,
      include: ['src/**/*'],
      exclude: ['tests/**/*', '**/*.test.ts'],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'Fetchor',
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
    rollupOptions: {
      external: [],
      output: [
        {
          format: 'es',
          entryFileNames: 'fetchor.esm.js',
          globals: {},
        },
        {
          format: 'umd',
          entryFileNames: 'fetchor.umd.js',
          name: 'Fetchor',
          globals: {},
        },
      ],
      treeshake: {
        moduleSideEffects: false,
      },
    },
    // 启用源码映射用于调试
    sourcemap: false,
    // 优化构建性能
    target: 'es2015',
  },
  // 优化依赖预构建
  optimizeDeps: {
    include: [],
  },
});
